package fundation.lambda;

import org.junit.Test;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;

/**
 * lambda表达式
 */
public class LambdaExpressDemo {

    /**
     * lambda表达式的形式
     */
    @Test
    public void test01() {
        //无参 无返回
        Runnable runnable = () -> System.out.println("无参无返回Lambda测试");
        runnable.run();

        System.out.println();

        //有参无返回,也可以通过函数的形式写
//        Consumer<String> consumer = o -> System.out.println("有参无返回Lambda测试。参数为：" + o);
        Consumer<String> consumer = System.out::println;//Method references 方法引用替代lambda 参考 http://zh.lucida.me/blog/java-8-lambdas-insideout-language-features/
        consumer.accept("parama1");


        System.out.println();
        //有参有返回
        Comparator comparator = (o1, o2) -> o1.equals(o2)?0:1;
        System.out.println("有参有返回： "+comparator.compare(12,13));



    }
}
